<template>
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="8" :sm="12">
            <a-form-item label="">
              <a-input-group compact>
                <a-select v-model="queryParam.searchField">
                  <a-select-option value="projectNo"> 项目编号 </a-select-option>
                  <a-select-option value="projectName"> 项目名称 </a-select-option>
                </a-select>
                <a-input-search
                  style="width: 78%"
                  v-model="queryParam.keyword"
                  @search="searchQuery"
                  placeholder="请按照关键字进行搜索"
                />
              </a-input-group>
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="8">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button-group>
                <a-button :type="queryParam.timeFlag == '1' ? 'primary' : ''" @click="handleSearchTime(1)"
                  >本周</a-button
                >
                <a-button :type="queryParam.timeFlag == '2' ? 'primary' : ''" @click="handleSearchTime(2)"
                  >本月</a-button
                >
                <a-button :type="queryParam.timeFlag == '3' ? 'primary' : ''" @click="handleSearchTime(3)"
                  >全部</a-button
                >
              </a-button-group>
              <a-button type="primary" @click="showSearchForm = true" icon="search" style="margin-left: 30px"
                >高级查询</a-button
              >
              <a-button
                type="primary"
                @click="handlePostExportXls('信息迭代版本报表')"
                icon="download"
                style="margin-left: 10px"
                >导出</a-button
              >
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>

      <a-modal
        :visible="showSearchForm"
        width="70vw"
        :bodyStyle="{ padding: '10px' }"
        title="高级查询"
        @ok="handleToSearch"
        @cancel="showSearchForm = false"
      >
        <a-form-model ref="ruleForm" :label-col="labelCol" :wrapper-col="wrapperCol">
          <a-row :gutter="24">
            <a-col :span="8">
              <a-form-model-item label="任务单编号">
                <a-input v-model="queryParam.taskNo" />
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="项目编号">
                <a-input v-model="queryParam.projectNo" />
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="计划完成时间">
                <a-range-picker v-model="planStartDate" @change="startChange" />
              </a-form-model-item>
            </a-col>
          </a-row>

          <a-row :gutter="24">
            <a-col :span="8">
              <a-form-model-item label="项目名称">
                <a-input v-model="queryParam.projectName" />
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="项目经理">
                <a-input v-model="queryParam.projectManager" />
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="实际完成时间">
                <a-range-picker v-model="completeDate" @change="completeChange" />
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>
      </a-modal>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator"></div>
    <div class="container">
      <a-table
        ref="table"
        bordered
        size="middle"
        :scroll="{ x: true }"
        :rowKey="
          (record, index) => {
            return index
          }
        "
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange"
      >
        <template slot="status" slot-scope="text, record">
          {{ initStatusText(record) }}
        </template>
        <template slot="taskNo" slot-scope="text, record">
          <span style="color: blue" @click="openTaskUrl(record)">{{ text }}</span>
        </template>
        <template slot="projectNo" slot-scope="text, record">
          <span style="color: blue" @click="openProjectUrl(record)">{{ text }}</span>
        </template>
        <template slot="endDate" slot-scope="text">
          <span>{{ formatDate(text) }}</span>
        </template>
        <template slot="maxCompletionDate" slot-scope="text, record">
          <span v-if="!record.taskId">
            {{ formatDate(text) }}
          </span>
          <span v-if="record.taskId && record.status == '2' && record.hasSendNotice && record.hasSendNotice != '1'">{{
            formatDate(text)
          }}</span>
        </template>
      </a-table>
    </div>
  </a-card>
</template>


<script>
import { JeecgListMixin } from '@/mixins/JeecgListSearchMixin'
import moment from 'moment'
export default {
  name: 'itAdjustmentList',
  mixins: [JeecgListMixin],
  components: {},
  data() {
    return {
      description: '信息迭代版本报表',
      /* 勾选导出参数 */
      rowKey: 'id',
      busType: 'itAdjustmentList',
      columns: [
        {
          title: '任务单编号',
          dataIndex: 'taskNo',
          key: 'taskNo',
          width: '10%',
          align: 'center',
          scopedSlots: { customRender: 'taskNo' },
        },
        {
          title: '项目编号',
          dataIndex: 'projectNo',
          key: 'projectNo',
          width: '10%',
          align: 'center',
          scopedSlots: { customRender: 'projectNo' },
        },
        {
          title: '项目名称',
          dataIndex: 'projectName',
          key: 'projectName',
          align: 'center',
        },
        {
          title: '版本号',
          dataIndex: 'versionNo',
          key: 'versionNo',
          align: 'center',
          width: '7%',
        },
        {
          title: '任务单名称',
          dataIndex: 'taskName',
          key: 'taskName',
          align: 'center',
          width: '20%',
        },
        {
          title: '计划完成时间',
          dataIndex: 'endDate',
          key: 'endDate',
          align: 'center',
          width: '7%',
          scopedSlots: { customRender: 'endDate' },
        },
        {
          title: '实际完成时间',
          dataIndex: 'maxCompletionDate',
          key: 'maxCompletionDate',
          align: 'center',
          width: '7%',
          scopedSlots: { customRender: 'maxCompletionDate' },
        },
        {
          title: '质量分',
          dataIndex: 'qualityScore',
          key: 'qualityScore',
          align: 'center',
          width: '7%',
        },
        {
          title: '测试结果',
          dataIndex: 'testConfirmStr',
          key: 'testConfirmStr',
          align: 'center',
          width: '7%',
        },
        {
          title: '项目经理',
          dataIndex: 'projectManager',
          key: 'mgTypeName',
          align: 'center',
          width: '7%',
        },
      ],
      url: {
        list: '/projectWorkTask/queryItReportInReportCenter',
        exportXlsUrl: '/projectWorkTask/itReportExport',
      },
      showSearchForm: false,
      keyword: '',
      labelCol: { span: 8 },
      wrapperCol: { span: 15 },
      queryParam: {
        searchField: 'projectNo',
        timeFlag: '1',
        startOneTime: null,
        startTweTime: null,
        completeOneTime: null,
        completetTwoTime: null,
      },
      planStartDate:[],
      completeDate:[],
    }
  },
  mounted() {},
  computed: {},
  methods: {
    initStatusText(record) {
      if (record.status == '1') {
        return '创建中'
      }
      if (record.status == '2' && record.hasSendNotice && record.hasSendNotice != '1') {
        return '已完成'
      } else {
        return '实施中'
      }
    },
    formatDate(date) {
      return date ? moment(date).format('YYYY-MM-DD') : ''
    },
    openTaskUrl(record) {
      if (record.taskId) {
        let urlJump = this.$router.resolve({ path:`/projectTaskDetail?id=` + record.taskId})
        window.open(urlJump.href, '_blank')
      } else {
        let urlJump = this.$router.resolve({ path:`/projectReportHome?projectBuildId=` + record.projectBuildId})
        window.open(urlJump.href, '_blank')
      }
    },
    openProjectUrl(record) {
      let urlJump = this.$router.resolve({ path:`/approval?projectBuildId=` + record.projectBuildId})
      window.open(urlJump.href, '_blank')
    },
    handleToSearch() {
      this.showSearchForm = false
      this.searchQuery()
    },
    searchReset() {
      this.queryParam = {}
      this.queryParam.searchField = 'projectNo'
      this.queryParam.timeFlag = '1'
      this.queryParam.startOneTime = null
      this.queryParam.startTweTime = null
      this.queryParam.completeOneTime = null
      this.queryParam.completetTwoTime = null
      this.planStartDate = undefined
      this.completeDate = undefined
      this.handleToSearch()
    },
    handleSearchTime(time) {
      if (this.tableLoading) {
        return
      }
      this.queryParam.timeFlag = time
      this.handleToSearch()
    },
    showLength(item, len) {
      if (!item || item.length <= len) {
        return item
      }
      return item.substring(0, len) + '...'
    },
    startChange(date ,dateString) {
      console.log(dateString)
      if (dateString && dateString.length > 0) {
        this.queryParam.startOneTime = dateString[0]
        this.queryParam.startTweTime = dateString[0]
      }
    },
    completeChange(date ,dateString) {
      console.log(dateString)
      if (dateString && dateString.length > 0) {
        this.queryParam.completeOneTime = dateString[0]
        this.queryParam.completetTwoTime = dateString[0]
      }
    }
  },
}
</script>
<style lang="less" scoped>
@import '~@assets/less/common.less';
@import '~@assets/less/hte-main.less';
/deep/ .ant-form-item-label{
  background: white;
}
@media (max-width: 1170px) {
  .page-main .container section .list-content > div.flex-num1-box {
    flex-wrap: wrap;
    > div {
      &:nth-child(1),
      &:nth-child(2) {
        width: 48%;
      }
      &:nth-child(3) {
        width: 100%;
        justify-content: flex-start;
        > span {
          margin-right: 20px;
          margin-left: 0;
        }
      }
    }
  }
  .page-main .container section .list-content > div.flex-num2-box {
    display: block;
    margin-top: 0;
  }
}
</style>